import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2022-10-18
 * Time: 8:37
 */
class Person {
    public int age;//成员属性 实例变量
    public String name;
    public String sex;
    public void eat() {//成员方法
        System.out.println("吃饭!");
    }
    public void sleep() {
        System.out.println("睡觉!");
    }
}
public class TestDemo {
    public static void main(String[] args) {
        Person person = new Person();//通过new实例化对象
        person.eat();//成员方法调用需要通过对象的引用调用
        person.sleep();
        //产生对象     实例化对象
        Person person2 = new Person();
        Person person3 = new Person();
    }
    public static void main6(String[] args) {
        int[][] array = {
                {1, 2, 3, 4},
                {5, 6, 7, 8},
                {9, 10, 11, 12}
        };
        System.out.println(Arrays.deepToString(array));
    }
    public static int[] copyArray(int[] array){
        int[] copy = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copy[i] = array[i];
        }
        return copy;
    }
    public static void main5(String[] args) {
        int[] array = {1,2,3,4,5,7,8,10};
        int[] ret = copyArray(array);
        System.out.println(Arrays.toString(ret));
    }
    public static void transfrom(int[] array){
        int left = 0;
        int right = array.length-1;
        while (left < right){
            //找奇数 停下来
            while (left < right && array[left] % 2 == 0){
                left++;
            }
            //找偶数 停下来
            while (left < right && array[right] % 2 != 0){
                right--;
            }
            //交换 奇数和偶数
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
        }
    }
    public static void main4(String[] args) {
        int[] array = {1,3,5,4,7,10,9,8,6};
        transfrom(array);
        System.out.println(Arrays.toString(array));
    }
    public static void reverse(int[] array){
        int i = 0;
        int j = array.length-1;
        while (i < j) {
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
            i++;
            j--;
        }
    }
    public static void main3(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        reverse(array);
        System.out.println(Arrays.toString(array));
    }
    public static void bubbleSort(int[] array){
        for (int i = 0; i < array.length; i++) {
            boolean flg = false;
            for (int j = 0; j < array.length-i-1; j++) {
                if(array[j] >array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
            //flg == false
            if (!flg) {
                return;
            }
        }
    }
    public static void main2(String[] args) {
        int[] array = {1,5,3,9,7,15,13,11};
//        bubbleSort(array);
        Arrays.fill(array,2,6,99);
        System.out.println(Arrays.toString(array));
    }
    public static boolean isSorted(int[] array){
        for (int i = 0; i < array.length - 1; i++) {
            if (array[i] > array[i+1]){
                return false;
            }
        }
        return true;
    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,10,5,6};
        System.out.println(isSorted(array));
    }
}
